package com.xz.stu.server.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xz.stu.server.vo.courseSelection.*;
import com.xz.stu.server.service.CourseSelectionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "课程信息管理")
@RestController
@RequestMapping("admin-api/school/courseSelection")
public class CourseSelectionController {

    @Resource
    private CourseSelectionService courseSelectionService;

    @PostMapping("/create")
    @Operation(summary = "创建课程信息")
    public CommonResult<Long> createCourseSelection(@Valid @RequestBody CourseSelectionCreateReqVO createReqVO) {
        return success(courseSelectionService.createCourseSelection(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新课程信息")
    public CommonResult<Boolean> updateCourseSelection(@Valid @RequestBody CourseSelectionUpdateReqVO updateReqVO) {
        courseSelectionService.updateCourseSelection(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除课程信息")
    public CommonResult<Boolean> deleteCourseSelection(@PathVariable List<Long> id) {
        courseSelectionService.deleteCourseSelection(id);
        return success(true);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "获取课程信息详情")
    public CommonResult<CourseSelectionRespVO> getCourseSelection(@PathVariable Long id) {
        return success(courseSelectionService.getCourseSelection(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获得课程信息列表")
    public CommonResult<List<CourseSelectionRespVO>> getCourseSelectionList(@Valid CourseSelectionListReqVO listReqVO) {
        return success(courseSelectionService.getCourseSelectionList(listReqVO));
    }

    @GetMapping("/listPage")
    @Operation(summary = "获得课程信息列表-分页")
    public CommonResult<PageResult<CourseSelectionRespVO>> getCourseSelectionListPage(@Valid CourseSelectionListPageReqVO listReqVO) {
        return success(courseSelectionService.getCourseSelectionListPage(listReqVO));
    }
    @GetMapping("/selectCourse/{id}")
    @Operation(summary = "学生选课")
    public CommonResult<Boolean> selectCourse(@PathVariable Long id){
        return success(courseSelectionService.selectCourse(id));
    }
    @GetMapping("/teacher/courses")
    @Operation(summary = "教师查看自己教授的课程")
    public CommonResult<List<CourseSelectionRespVO>> getCourseSelectionListByTeacherId(@RequestParam String termId){
        return success(courseSelectionService.getCourseSelectionListByTeacherId(Long.valueOf(termId)));
    }
    @GetMapping("/teacher/students/{courseId}")
    @Operation(summary = "课程所属学生")
    public CommonResult<List<CourseSelectionStudentRespVO>> getCourseSelectionStudents(@PathVariable Long courseId){
        return success(courseSelectionService.getCourseSelectionStudents(courseId));
    }
    @PostMapping("teacher/updateAndAddScore")
    @Operation(summary = "教师更新学生成绩")
    public CommonResult<Boolean> updateAndAddScore(@RequestBody CourseSelectionUpdateAndAddScoreReqVO updateAndAddScoreReqVO){
        return success(courseSelectionService.updateAndAddScore(updateAndAddScoreReqVO));
    }

}
